草庐IT

C++ make_shared 不可用

全部标签

go - http.Client 和 goroutines 的不可预测的结果

我是Golang的新手,试图构建一个系统,从一组url中获取内容并使用正则表达式提取特定行。当我用goroutines包装代码时,问题就开始了。我得到了不同数量的正则表达式结果,并且许多提取的行都是重复的。max_routines:=3sem:=make(chanint,max_routines)//tocontrolthenumberofworkingroutinesvarwgsync.WaitGroupch_content:=make(chanstring)client:=http.Client{}fori:=2;;i++{//fortestingifi>5{break}//loo

json - 使用不可打印的 ASCII 字符解码 JSON

如何使用Go解码包含不可打印的ASCII字符的JSON字符串?例如testJsonString:="{\"test_one\":\"123\x10456\x0B789\v123\a456\"}"vardatmap[string]interface{}err:=json.Unmarshal([]byte(testJsonString),&dat)iferr!=nil{panic(err)}产量:panic:invalidcharacter'\x10'instringliteralgoroutine1[running]:main.main()/tmp/sandbox903140350/ma

go - 导出的方法在同一个包中不可用

我有一个小的golang项目,在main.go文件中有一些处理程序引用session.go文件中的session相关方法。两者在文件顶部都有packagemain。session.go文件中的函数都以大写字母开头(即它们是公共(public)/导出方法)。然而,当我运行main.go文件时,它说位于session.go中并从main.go调用的方法是未定义。为什么会这样,如何解决。我正在运行项目gorunmain.go主.gofunclogout(whttp.ResponseWriter,r*http.Request){ClearSession(w,r)....}session.gof

go - 当变量已经声明时,为什么我必须将类型传递给 make 函数?

我想使用匿名结构来做一些事情。varusers[]struct{Namestring`json:"name,omitempty"`Ageint}我必须再次编写类型来设置值users=make([]struct{Namestring`json:"name,omitempty"`Ageint},0,10)如果我坚持使用匿名结构,有没有办法让它更体面?(如果不是,我想知道为什么golang的设计会做出这样的功能...) 最佳答案 匿名结构对于一次性使用非常方便。如果您多次使用它,请定义一个命名结构类型。如果你只在一个函数中使用它,你可以在

go - String 类型声明与 string 不可比

我有一个别名类型“LogLevel”,它是一个字符串:typeLogLevelstringconst(InfoLevelLogLevel="info"DebugLevelLogLevel="debug"WarnLevelLogLevel="warn"ErrorLevelLogLevel="error"PanicLevelLogLevel="panic"FatalLevelLogLevel="fatal")现在我想做一个switchcase来根据用户输入检查这些常量:switchstrings.ToLower(input){case"",InfoLevel:returnzap.NewAt

go - Go sync.pool 比 make 慢很多吗?

我尝试使用sync.Pool来重用[]byte。但事实证明它比make慢。代码:packagemainimport("sync""testing")funcBenchmarkMakeStack(b*testing.B){forN:=0;N结果:$gotestpool_test.go-bench=.-benchmemBenchmarkMakeStack-420000000000.29ns/op0B/op0allocs/opBenchmarkBytePool-410000000017.2ns/op0B/op0allocs/op根据Go文档,sync.Pool应该更快,但我的测试显示并非如此

Go Modules - 本地包不可访问?

所以,我是Go的新手。我创建了一个go.mod文件modulegithub.com/austin/test-project我在最新的git提交中添加了一个标签v0.0.1。根据我试图理解的一些示例,我将这些导入添加到我的go文件中,其中common是一个包,dynamo是另一个包,而导入来自名为main的第三个包。import("github.com/austin/test-project/common""github.com/austin/test-project/db/dynamo/playerstateddb""github.com/austin/test-project/db/

bash - ./make.bash ubuntu->windows 的 Go lang 安装问题

我尝试搜索并找到了很多与我的问题相关的主题,但没有一个是我可以成功的。我可以gorun和goget没有问题,但我需要编译到windows中,我遇到问题请看下面mikhail@mikhail-desktop:/usr/lib/go/src$sudo./make.bash#BuildingCbootstraptool.cmd/distgotooldist:$GOROOTisnotsetcorrectlyornotexportedGOROOT=/usr/share/go/usr/share/go/include/u.hdoesnotexistmikhail@mikhail-desktop:/

go - Golang 中 Make string 末尾的 `json:"make"` 是什么意思?

这个问题在这里已经有了答案:Whatistheusageofbacktickingolangstructsdefinition?[duplicate](2个答案)关闭6年前。我正在处理一些Golang源代码,并且对下面的程序语法感到困惑。Golang中Makestring末尾的json:"make"是什么意思?typeVehiclestruct{Makestring`json:"make"`Modelstring`json:"model"`Regstring`json:"reg"`VINint`json:"VIN"`Ownerstring`json:"owner"`Scrappedbo

go - 理解代码 : Sharing resources by communicating

我一直在努力理解中的代码https://golang.org/doc/codewalk/sharemem/虽然我了解了大部分关于通过channel传递资源的部分,但我无法理解程序运行的无限循环。当轮询函数中的“输入”channel(从主函数接收)时,程序如何无限执行轮询函数)只运行3个pollergo例程?我得到了StateMonitor的想法,它具有无限循环的匿名go函数。但它无法在不从Poller函数接收的情况下更新LogState。我假设程序无限地对url执行Get请求。为了确认我所理解的没有错,我通过打开和关闭wifi来测试程序以查看日志是否发生变化。令我惊讶的是,它确实如此,